package com.nt.thah.controller;

import com.alibaba.fastjson.JSONObject;
import com.nt.thah.requestparam.BaseParam;
import com.nt.thah.requestparam.ProductParam;
import com.nt.thah.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description: 产品管理
 * @author: ls
 * @Date: 2020/7/8 16:12
 */
@Api(tags = "产品管理")
@RestController
@RequestMapping("/product")
@Validated
public class ProductController {

    @Resource
    private ProductService productServiceImpl;

    @ApiOperation(value = "获取产品列表")
    @PostMapping("/getList")
    public Map<String, Object> getList(BaseParam param) {
        return productServiceImpl.getList(param);
    }

    @ApiOperation(value = "获取产品详情")
    @PostMapping("/getProductDetail")
    public JSONObject getProductDetail(Integer id) {
        Assert.notNull(id, "产品id不能为空");
        return productServiceImpl.getProductDetail(id);
    }

    @ApiOperation(value = "保存产品信息")
    @PostMapping("/save")
    public void save(@RequestBody ProductParam param) {
        productServiceImpl.save(param);
    }

    @ApiOperation(value = "更新产品信息")
    @PostMapping("/update")
    public void update(@RequestBody ProductParam param) {
        productServiceImpl.update(param);
    }

}
